package com.dongjiantong.web.boss.handler;

import com.dongjiantong.common.exceptions.OPServerException;
import com.dongjiantong.common.model.Response;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 异常捕获处理
 * Created by cao on 2017/10/27.
 */
@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value=Exception.class)
    @ResponseBody
    public Response exceptionHandle(Exception e)
    {
        if(e instanceof OPServerException)
        {
            OPServerException opServerException =(OPServerException)e;
            return Response.fail(opServerException.getCode(),opServerException.getReason());
        }

        return Response.fail(e.getMessage());
    }


}
